【pyqt5学习】

您所在的位置:网站首页 qt qlineedit 【pyqt5学习】

【pyqt5学习】

2023-06-04 11:33| 来源: 网络整理| 查看: 265

目录

1、回显模式

2、成果显示

3、知识点

1)FormLayout布局添加addRow方法

2)在输入框显示灰色提示字体,输入内容时消失setPlaceholderText

3)设置回显模式setEchoMode

 

 4、完整代码

1、回显模式

QLineEdit控件的主要功能是输入一行文本内容,输入内容的过程中内容显示的方式称之为回显,支持四种回显方式。

1)正常,即输入什么显示什么(Normal)

2)不显示,用户输入什么在输入框中不显示,用户也不知道输入了什么,少用(NoEcho)

3)密码形式,即用户输入的时候,在输入框中显示的是黑点(PassWord)

4)PasswordEchoOnEdit——在编辑这个输入框的时候显示,不编辑时编程黑点

2、成果显示

开始界面

输入文本后,光标在PassWordEchoOnEdit输入框时,可以看到密码时可以看到的

 

光标不在PassWordEchoOnEdit输入框时,可以看到密码时不可以看到的 

 

注:并且再次编辑PassWordEchoOnEdit输入框时,会先将输入框的内容全部清空,然后重新输入新的内容

 

3、知识点 1)FormLayout布局添加addRow方法

支持多种方法

# 将控件放入布局中 formLayout.addRow("Normal",normalLineEdit) formLayout.addRow("noEcho",noEchoLineEdit) formLayout.addRow("Password",PasswordLineEdit) formLayout.addRow("PasswordEchoOnEdit",PasswordEchoOnEditLineEdit) 2)在输入框显示灰色提示字体,输入内容时消失setPlaceholderText # 在输入框中显示灰色字体,用于提示 normalLineEdit.setPlaceholderText("Normal") noEchoLineEdit.setPlaceholderText("noEcho") PasswordLineEdit.setPlaceholderText("Password") PasswordEchoOnEditLineEdit.setPlaceholderText("PasswordEchoOnEdit")

3)设置回显模式setEchoMode # 设置回显模式 normalLineEdit.setEchoMode(QLineEdit.Normal) noEchoLineEdit.setEchoMode(QLineEdit.NoEcho) PasswordEchoOnEditLineEdit.setEchoMode(QLineEdit.PasswordEchoOnEdit) PasswordLineEdit.setEchoMode(QLineEdit.Password)    4、完整代码 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2022/5/20 16:44 # @Author : @linlianqin # @Site : # @File : QLineEdit_learn.py # @Software: PyCharm # @description: from PyQt5.QtWidgets import QDialog,QLabel,QLineEdit,QPushButton,QFormLayout,QApplication,QWidget class QLineEditLearn(QWidget): def __init__(self): super(QLineEditLearn, self).__init__() self.InitUI() # 初始化界面 def InitUI(self): self.setWindowTitle("QLineEdit文本回显学习") # 创建多个输入框 normalLineEdit = QLineEdit() noEchoLineEdit = QLineEdit() PasswordLineEdit = QLineEdit() PasswordEchoOnEditLineEdit = QLineEdit() # 创建一个form布局 formLayout = QFormLayout() # 将控件放入布局中 formLayout.addRow("Normal",normalLineEdit) formLayout.addRow("noEcho",noEchoLineEdit) formLayout.addRow("Password",PasswordLineEdit) formLayout.addRow("PasswordEchoOnEdit",PasswordEchoOnEditLineEdit) # 在输入框中显示灰色字体,用于提示 normalLineEdit.setPlaceholderText("Normal") noEchoLineEdit.setPlaceholderText("noEcho") PasswordLineEdit.setPlaceholderText("Password") PasswordEchoOnEditLineEdit.setPlaceholderText("PasswordEchoOnEdit") # 设置回显模式 normalLineEdit.setEchoMode(QLineEdit.Normal) noEchoLineEdit.setEchoMode(QLineEdit.NoEcho) PasswordEchoOnEditLineEdit.setEchoMode(QLineEdit.PasswordEchoOnEdit) PasswordLineEdit.setEchoMode(QLineEdit.Password) # 将布局放入到里面 self.setLayout(formLayout) if __name__ == '__main__': import sys app = QApplication(sys.argv) demoWin = QLineEditLearn() demoWin.show() sys.exit(app.exec_())



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3